home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCSmallEiffel / lib_se / cecil_pool.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.6 KB  |  211 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CECIL_POOL
  17.    --
  18.    -- Unique global object in charge of CECIL calls.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.    
  25.    -- Internal SmallEiffel entry points :
  26.    se_cecil_list: FIXED_ARRAY[RUN_FEATURE];
  27.    se_cecil_name: FIXED_ARRAY[STRING];
  28.  
  29.    -- User's entry points from cecil file :
  30.    user_cecil_list: FIXED_ARRAY[RUN_FEATURE];
  31.    user_cecil_name: FIXED_ARRAY[STRING];
  32.  
  33.    user_path_h: STRING;
  34.  
  35. feature {SMALL_EIFFEL}
  36.  
  37.    fill_up is
  38.       local
  39.      t: TYPE;
  40.      rta: FIXED_ARRAY[TYPE];
  41.      fna: FIXED_ARRAY[FEATURE_NAME];
  42.      rf: RUN_FEATURE;
  43.      i: INTEGER;
  44.       do
  45.      -- Internals :
  46.      if run_control.no_check then
  47.         !!se_cecil_list.with_capacity(1);
  48.         !!se_cecil_name.with_capacity(1);
  49.         -- To be sure that GENERAL.print is alive :
  50.         se_cecil_name.add_last("se_print");
  51.         rf := type_any.run_class.get_feature_with(us_print);
  52.         se_cecil_list.add_last(rf);
  53.         switch_collection.update_with(rf);
  54.      end;
  55.      -- For the user :
  56.      if run_control.cecil_path /= Void then
  57.         !!user_cecil_list.with_capacity(4);
  58.         !!user_cecil_name.with_capacity(4);
  59.         user_path_h := eiffel_parser.connect_to_cecil;
  60.         from
  61.            !!rta.with_capacity(4);
  62.            !!fna.with_capacity(4);
  63.         until
  64.            eiffel_parser.end_of_input
  65.         loop
  66.            user_cecil_name.add_last(eiffel_parser.parse_c_name);
  67.            rta.add_last(eiffel_parser.parse_run_type);
  68.            check
  69.           nb_errors = 0
  70.            end;
  71.            fna.add_last(eiffel_parser.parse_feature_name);
  72.            check
  73.           nb_errors = 0
  74.            end;
  75.         end;
  76.         eiffel_parser.disconnect;
  77.         echo.put_string("Loading cecil features.%N");
  78.         from
  79.            i := 0;
  80.         until
  81.            i > rta.upper
  82.         loop
  83.            t := rta.item(i).to_runnable(type_any);
  84.            rf := t.run_class.get_feature(fna.item(i));
  85.            user_cecil_list.add_last(rf);
  86.            switch_collection.update_with(rf);
  87.            i := i + 1;
  88.         end;
  89.      end;
  90.       end;
  91.  
  92. feature {C_PRETTY_PRINTER}
  93.  
  94.    c_define_internals is
  95.       do
  96.      if se_cecil_list /= Void then
  97.         echo.put_string("Cecil (internal use) :%N");
  98.         c_define_for_list(se_cecil_list,se_cecil_name);
  99.      end;
  100.       end;
  101.  
  102.    c_define_users is
  103.       do
  104.      if user_cecil_list /= Void then
  105.         echo.put_string("Cecil (for user) :%N");
  106.         cpp.connect_cecil_out_h(user_path_h);
  107.         c_define_for_list(user_cecil_list,user_cecil_name);
  108.         cpp.disconnect_cecil_out_h;
  109.      end;
  110.       end;
  111.  
  112. feature {NONE}
  113.  
  114.    c_define_for_list(cecil_list: FIXED_ARRAY[RUN_FEATURE];
  115.              cecil_name: FIXED_ARRAY[STRING]) is
  116.       require
  117.      cecil_name.count = cecil_list.count
  118.       local
  119.      i: INTEGER;
  120.       do
  121.      from
  122.         i := cecil_list.upper;
  123.      until
  124.         i < 0
  125.      loop
  126.         c_define_for(cecil_name.item(i),cecil_list.item(i));
  127.         i := i - 1;
  128.      end;
  129.       end;
  130.  
  131. feature {NONE}
  132.    
  133.    c_define_for(c_name: STRING; rf: RUN_FEATURE) is
  134.       require
  135.      not c_name.empty;
  136.      rf /= Void
  137.       local
  138.      running: ARRAY[RUN_CLASS];
  139.      rfct, rfrt: TYPE;
  140.      rfname: FEATURE_NAME;
  141.      rfargs: FORMAL_ARG_LIST;
  142.      cecil_target: CECIL_TARGET;
  143.      cecil_arg_list: CECIL_ARG_LIST;
  144.       do
  145.      rfct := rf.current_type;
  146.      rfrt := rf.result_type;
  147.      rfname := rf.name;
  148.      rfargs := rf.arguments; 
  149.      echo.put_string(rfct.run_time_mark);
  150.      echo.put_character('%T');
  151.      echo.put_character('.');
  152.      echo.put_string(rfname.to_string);
  153.      echo.put_character('%N');
  154.      -- (1) ------------------------- Define Cecil heading :
  155.      tmp_string.clear;
  156.      if rfrt /= Void then
  157.         rfrt.c_type_for_external_in(tmp_string);
  158.      else
  159.         tmp_string.append(fz_void);
  160.      end;
  161.      tmp_string.extend(' ');
  162.      tmp_string.append(c_name);
  163.      tmp_string.extend('(');
  164.      rfct.c_type_for_external_in(tmp_string);
  165.      tmp_string.extend(' ');
  166.      tmp_string.extend('C');
  167.      if rfargs /= Void then
  168.         tmp_string.extend(',');
  169.         rfargs.external_prototype(tmp_string);
  170.      end;
  171.      tmp_string.extend(')');
  172.      cpp.put_c_heading(tmp_string);
  173.      cpp.swap_on_c;
  174.      -- (2) ------------------------- Define body of Cecil :
  175.      running := rfct.run_class.running;
  176.      if running = Void then
  177.         eh.add_type(rfct," not created (type is not alive).");
  178.         eh.append("Empty Cecil function ");
  179.         eh.append(rfct.run_time_mark);
  180.         eh.append(rfname.to_key);
  181.         eh.append(".");
  182.         eh.print_as_warning;
  183.      end;
  184.      if rfrt /= Void then
  185.         cpp.put_string("return ");
  186.      end;
  187.      !!cecil_target.make(rf);
  188.      if rf.arg_count > 0 then
  189.         !!cecil_arg_list.make(rf);
  190.      end;
  191.      if rfct.is_expanded then
  192.         cpp.push_direct(rf,cecil_target,cecil_arg_list);
  193.         rf.mapping_c;
  194.         cpp.pop;
  195.      else
  196.         cpp.push_cpc(rf,running,cecil_target,cecil_arg_list);
  197.      end;
  198.      cpp.put_string(fz_00);
  199.      cpp.put_string(fz_12);
  200.       end;
  201.  
  202. feature {NONE}
  203.    
  204.    tmp_string: STRING is
  205.       once
  206.      !!Result.make(256);
  207.       end;
  208.  
  209. end -- CECIL_POOL
  210.  
  211.